<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function getPromise(value, delay = 1000) {
        return new Promise(resolve => setTimeout(resolve, delay, value))
    }

    // 在await的时候执行
    async function fn1() {
        for (let i = 0; i < 3; i++) {
            let result = await getPromise(20)
            console.log(result)
        }
    }

    // fn1()

    // 提前执行
    async function fn2() {
        let start = Date.now();
        let p1 = getPromise(20)
        let p2 = getPromise(20)
        let p3 = getPromise(20)
        console.log('费时间1',Date.now()-start)
        let r1 = await p1;
        let r2 = await p2;
        let r3 = await p3;
        console.log('费时间2',Date.now()-start)  // 上面需要费时间
        console.log(r1, r2, r3)
    }
    fn2()
</script>
</body>
</html>